home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / xwinc100.zip / CONTRIB-.00 / CONTRIB- / contrib / examples / Xaw / xrepeater.c < prev    next >
C/C++ Source or Header  |  1991-01-22  |  4KB  |  139 lines

  1. /*
  2.  * This an example of how to use the Repeater widget.
  3.  */
  4.  
  5. /*
  6.  * $XConsortium: xrepeater.c,v 1.5 91/01/22 19:24:56 gildea Exp $
  7.  *
  8.  * Copyright 1989 Massachusetts Institute of Technology
  9.  *
  10.  * Permission to use, copy, modify, distribute, and sell this software and its
  11.  * documentation for any purpose is hereby granted without fee, provided that
  12.  * the above copyright notice appear in all copies and that both that
  13.  * copyright notice and this permission notice appear in supporting
  14.  * documentation, and that the name of M.I.T. not be used in advertising or
  15.  * publicity pertaining to distribution of the software without specific,
  16.  * written prior permission.  M.I.T. makes no representations about the
  17.  * suitability of this software for any purpose.  It is provided "as is"
  18.  * without express or implied warranty.
  19.  *
  20.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  22.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  23.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  24.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  25.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26.  */
  27.  
  28. #include <stdio.h>
  29. #include <X11/Intrinsic.h>
  30. #include <X11/StringDefs.h>    /* Get standard string definations. */
  31.  
  32. #include <X11/Xaw/Repeater.h>
  33. #include <X11/Xaw/Cardinals.h>    
  34.  
  35. char *ProgramName;
  36.  
  37. String fallback_resources[] = { 
  38.     "*Repeater.Label:    Press Me",
  39.     NULL,
  40. };
  41.  
  42. static XrmOptionDescRec options[] = {
  43. {"-label",    "*Repeater.label",    XrmoptionSepArg,    NULL},
  44. {"-bitmap",    "*Repeater.bitmap",    XrmoptionSepArg,    NULL},
  45. {"-flash",    "*Repeater.flash",    XrmoptionNoArg,    (caddr_t) "on" },
  46. {"-decay",    "*Repeater.decay",    XrmoptionSepArg,    NULL},
  47. {"-initial",    "*Repeater.initialDelay",    XrmoptionSepArg,    NULL},
  48. {"-repeat",    "*Repeater.repeatDelay",    XrmoptionSepArg,    NULL},
  49. {"-minimum",    "*Repeater.minimumDelay",    XrmoptionSepArg,    NULL},
  50. };
  51.  
  52. static char *helpmsg[] = {
  53.     "-label string              button label",
  54.     "-bitmap name               button bitmap",
  55.     "-flash                     flash on repeats",
  56.     "-decay number              repeat decay in milliseconds",
  57.     "-initial number            initial delay in milliseconds",
  58.     "-repeat number             repeat delay in milliseconds",
  59.     "-minimum number            minimum repeat delay in milliseconds",
  60. NULL };
  61.  
  62. static void usage (app_con)
  63.     XtAppContext app_con;
  64. {
  65.     char **msg;
  66.  
  67.     XtDestroyApplicationContext (app_con);
  68.  
  69.     fprintf (stderr, "Usage:  %s [-options]\n", ProgramName);
  70.     fprintf (stderr, "\nwhere options include:\n");
  71.     for (msg = helpmsg; *msg; msg++) fprintf (stderr, "    %s\n", *msg);
  72.     fprintf (stderr, "\n");
  73.     exit(1);
  74. }
  75.  
  76. /*    Function Name: Select
  77.  *    Description: This function prints a message to stdout.
  78.  *    Arguments: w - ** UNUSED **
  79.  *                 call_data - ** UNUSED **
  80.  *                 client_data - ** UNUSED **
  81.  *    Returns: none
  82.  */
  83.  
  84. static int count = 0;
  85.  
  86. static void Select (w, client_data, call_data)
  87.     Widget w;
  88.     XtPointer call_data, client_data;
  89. {
  90.     printf ("Press #%d\n", ++count);
  91. }
  92.  
  93. static void Start (w, client_data, call_data)
  94.     Widget w;
  95.     XtPointer call_data, client_data;
  96. {
  97.     printf ("Starting...\n");
  98.     count = 0;
  99. }
  100.  
  101. static void Stop (w, client_data, call_data)
  102.     Widget w;
  103.     XtPointer call_data, client_data;
  104. {
  105.     printf ("...Stopping\n");
  106. }
  107.  
  108. main (argc, argv)
  109.     int argc;
  110.     char **argv;
  111. {
  112.     XtAppContext app_con;
  113.     Widget toplevel, repeater;
  114.  
  115.     ProgramName = argv[0];
  116.  
  117.     toplevel = XtAppInitialize(&app_con, "XRepeater",
  118.                    options, XtNumber(options),
  119.                    &argc, argv, fallback_resources,
  120.                    NULL, ZERO);
  121.  
  122.     if (argc != 1) usage (app_con);
  123.  
  124.     repeater = XtCreateManagedWidget("repeater", repeaterWidgetClass, toplevel,
  125.                     NULL, ZERO);
  126.  
  127.     /*
  128.      * Add a callback routine to the Repeater widget that will print
  129.      * the message "button selected" to stdout.
  130.      */
  131.  
  132.     XtAddCallback (repeater, XtNcallback, Select, NULL);
  133.     XtAddCallback (repeater, XtNstartCallback, Start, NULL);
  134.     XtAddCallback (repeater, XtNstopCallback, Stop, NULL);
  135.  
  136.     XtRealizeWidget(toplevel);
  137.     XtAppMainLoop(app_con);
  138. }
  139.